
"""
    tcp服务端2.0
"""
import socket

tcp_server_so = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

tcp_server_so.bind(("192.168.0.107", 8080))

tcp_server_so.listen(128)

while True:

    tcp_client_so, tcp_ip_port = tcp_server_so.accept()
    print("%s客户端已连接" % str(tcp_client_so))

    while True:
        recv_data = tcp_client_so.recv(1024)

        # 判断是否接受值为空，为空表示客户端已关闭
        if recv_data:
            recv_text = recv_data.decode("GBK")

            print("收到%s客户端的消息：%s" % (tcp_ip_port, recv_text))
        else:
            print("客户端已关闭")
            break

tcp_server_so.close()
